package com.example.javaee_blog.config;


import com.example.javaee_blog.model.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


@ResponseBody
@ControllerAdvice
public class ErrorHandler {
    @ExceptionHandler
    public Result handler(Exception e){
        return Result.fail(e.getMessage());
    }
//    第二种写法 - 查找注解中的异常
//    @ExceptionHandler(NullPointerException.class)
//    public Result handler1(Exception e){
//        return Result.fail(e.getMessage());
//    }
}
